#include "searchcapturemachine.h"

namespace PikaChess {
SearchCaptureMachine::SearchCaptureMachine(const Chessboard &chessboard)
    : m_chessboard { chessboard } { }

Move SearchCaptureMachine::getNextMove() {
  switch (this->m_phase) {
  case PHASE_CAPTURE_GEN:
    // 指明下一个阶段
    this->m_phase = PHASE_CAPTURE;
    // 生成吃子走法，使用MVVLVA对其进行排序
    this->m_totalMoves = this->m_chessboard.genCapMoves(this->m_moveList);
    std::sort(std::begin(this->m_moveList), std::begin(this->m_moveList) + this->m_totalMoves);
    // 直接下一步
    [[fallthrough]];

  case PHASE_CAPTURE:
    /* 遍历走法，逐个返回吃子走法 */
    while (this->m_nowMove < this->m_totalMoves) return this->m_moveList[this->m_nowMove++];
    // 如果没有了就下一步
    [[fallthrough]];

  default:
    return INVALID_MOVE;
  }
}
}
